package com.fourgirls.xiaoxiang.controller;


import com.fourgirls.xiaoxiang.exception.Result;
import com.fourgirls.xiaoxiang.pojo.Address.UserNameAddressVo;
import com.fourgirls.xiaoxiang.pojo.Collection.CollectionIdVo;
import com.fourgirls.xiaoxiang.pojo.Collection.CollectionVo;
import com.fourgirls.xiaoxiang.service.Collection.UserCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class CollectionController {

    @Autowired
    UserCollectionService userCollectionService;


    //---------------------------------------------------------------查询分割线--------------------------------------------------------

    /**
     * 查询address表中的所有数据(一对多的级联，查询user表中用户对应的收货地址)
     *
     * @return 查询的数据
     */
    @RequestMapping("findAllUserCollection")
    public Result findAllUserCollection(@RequestBody UserNameAddressVo userNameAddressVo) {
        return Result.ok().put("data", userCollectionService.findAllUserCollection(userNameAddressVo));
    }

    //---------------------------------------------------------------增加分割线--------------------------------------------------------

    /**
     * 增加collection表中的一条数据
     *
     * @param collectionVo
     * @return
     */
    @RequestMapping("addCollection")
    public Result addCollection(@RequestBody CollectionVo collectionVo) {
        return Result.ok().put("data", userCollectionService.addCollection(collectionVo));
    }

    //---------------------------------------------------------------增加分割线--------------------------------------------------------

    /**
     * 删除collection表中的一条数据
     *
     * @param collectionIdVo
     * @return
     */
    @RequestMapping("deleteCollection")
    public Result deleteCollection(@RequestBody CollectionIdVo collectionIdVo) {
        return Result.ok().put("data", userCollectionService.deleteCollection(collectionIdVo));
    }
}
